package com.ruoyi.web.controller.jjm;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjm.domain.GridMemeber;
import com.ruoyi.jjm.service.IGridMemeberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网格员Controller
 * 
 * @author tsr
 * @date 2020-07-15
 */
@Controller
@RequestMapping("/jjm/memeber")
public class GridMemeberController extends BaseController
{
    private String prefix = "jjm/memeber";

    @Autowired
    private IGridMemeberService gridMemeberService;

    @GetMapping()
    public String memeber()
    {
        return prefix + "/memeber";
    }

    /**
     * 查询网格员列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GridMemeber gridMemeber)
    {
        startPage();
        SysUser user = ShiroUtils.getSysUser();
        gridMemeber.setAreaId(user.getDeptId());
        List<GridMemeber> list = gridMemeberService.selectGridMemeberList(gridMemeber);
        return getDataTable(list);
    }

    /**
     * 导出网格员列表
     */
    @Log(title = "网格员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GridMemeber gridMemeber)
    {
        List<GridMemeber> list = gridMemeberService.selectGridMemeberList(gridMemeber);
        ExcelUtil<GridMemeber> util = new ExcelUtil<GridMemeber>(GridMemeber.class);
        return util.exportExcel(list, "memeber");
    }

    /**
     * 新增网格员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网格员
     */
    @Log(title = "网格员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GridMemeber gridMemeber)
    {
        GridMemeber query = new GridMemeber();
        query.setName(gridMemeber.getName());
        List<GridMemeber> result =  gridMemeberService.selectGridMemeberList(query);
        return toAjax(gridMemeberService.insertGridMemeber(gridMemeber));
    }

    /**
     * 修改网格员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GridMemeber gridMemeber = gridMemeberService.selectGridMemeberById(id);
        mmap.put("gridMemeber", gridMemeber);
        return prefix + "/edit";
    }

    /**
     * 修改保存网格员
     */
    @Log(title = "网格员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GridMemeber gridMemeber)
    {
        return toAjax(gridMemeberService.updateGridMemeber(gridMemeber));
    }

    /**
     * 删除网格员
     */
    @Log(title = "网格员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gridMemeberService.deleteGridMemeberByIds(ids));
    }
}
